home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / i / internet / software / lprsr / cookie.c next >
Encoding:
C/C++ Source or Header  |  1995-03-29  |  1.8 KB  |  81 lines

  1. #include <stdlib.h>
  2. #include <tos.h>
  3. #include "cookie.h"
  4. #include <stdio.h>
  5.  
  6. /* Orinigal:
  7.  #define NULL (void *)0L
  8. Patch: */
  9. #include <stddef.h>
  10. #define _cookiejar    *(long *)0x5A0L
  11.  
  12.  
  13. COOKIE *new_cookiejar(long n)
  14. {
  15.   register long superstack;
  16.   register COOKIE *jar,*newjar;
  17.   register long i,c;
  18.  
  19.   jar = get_cookiejar();
  20.   i=0;
  21.   if(jar) for(; jar[i].id != ENDCOOKIE; i++);  /* get size of old jar */
  22.   if(jar && jar[i].val > n) return(jar);  /* there isroom in jar */
  23.  
  24.   newjar = (COOKIE *)malloc(n*sizeof(COOKIE));/* alloc new jar */
  25.   if(jar && newjar) for(c=0; c<i; c++)
  26.   {  /* copy old jar */
  27.     newjar[c].id = jar[c].id;
  28.     newjar[c].val = jar[c].val;
  29.   }
  30.   newjar[i].id = ENDCOOKIE;  /* terminate new jar */
  31.   newjar[i].val = n;
  32.   superstack = Super((void *)0);
  33.   _cookiejar = (long)newjar;  /* install new jar */
  34.   Super((void*)superstack);
  35.   return(newjar);
  36. }
  37.  
  38. COOKIE *get_cookiejar(void)
  39. {
  40.   register long superstack;
  41.   register long cookieaddress;
  42.   
  43.   if(Super((void*)1L))
  44.   {
  45.     cookieaddress = _cookiejar;  /* return address of cookiejar */
  46.   }
  47.   else
  48.   {
  49.     superstack = Super(0L);
  50.     cookieaddress = _cookiejar;  /* return address of cookiejar */
  51.     Super((void*)superstack);
  52.   }
  53.     return (COOKIE *)cookieaddress;
  54. }
  55.  
  56. COOKIE *add_cookie(long id,long val)
  57. {
  58.   register COOKIE *jar;
  59.   if((jar = new_cookiejar(8L))==NULL) return(NULL);
  60.   while(jar->id != ENDCOOKIE) jar++;  /* search end of cookiejar */
  61.   jar->id = id;
  62.   (jar+1)->val = jar->val;  /* keep size of jar */
  63.   jar->val = val;
  64.   (jar+1)->id = ENDCOOKIE;
  65.   return(jar);
  66. }
  67.  
  68.  
  69. COOKIE *get_cookie(long id)
  70. {
  71.   register COOKIE *jar;
  72.   if((jar = get_cookiejar()) == NULL) return(NULL);
  73.   while(jar->id)
  74.   {
  75.     if(jar->id == id) return(jar);  /* find cookie */
  76.     jar++;
  77.   }
  78.   return(NULL);
  79. }
  80.  
  81.